/* 对撞指针 */
/* leetcode 344. 反转字符串*/

var reverseVowels = function(s) {
    if(s.length <= 1){
        return s;
    }
    let i = 0,len = s.length -1,j = len - i,result = Array(s.length);
    let  yy = new Set(['a','e','i','o','u','A','E','I','O','U']);
    while (i < j) {
        while (!yy.has(s[i])){
            result[i] = s[i];
            i++;
        }
        while ( i < j && !yy.has(s[j])){
            result[j] = s[j];
            j--;
        }
        if(i < j && yy.has(s[i]) && yy.has(s[j])){
            result[i] = s[j];
            result[j] = s[i];
            i++;
            j--;
        }
        if(i === j){
            result[i] = s[i];
        }
    }
    return result.join('');
};

console.log(reverseVowels("hello"));
console.log(reverseVowels("leetcode"));
console.log(reverseVowels(".,"));
console.log(reverseVowels("a,"));
console.log(reverseVowels(".a"));
console.log(reverseVowels("a.b,."));